package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CheckInLeave;
import com.ruoyi.system.service.ICheckInLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老人请假管理Controller
 *
 * @author ruoyi
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/system/leave")
public class CheckInLeaveController extends BaseController
{
    @Autowired
    private ICheckInLeaveService checkInLeaveService;

    /**
     * 查询老人请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckInLeave checkInLeave)
    {
        startPage();
        List<CheckInLeave> list = checkInLeaveService.selectCheckInLeaveList(checkInLeave);
        return getDataTable(list);
    }

    /**
     * 导出老人请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:export')")
    @Log(title = "老人请假管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckInLeave checkInLeave)
    {
        List<CheckInLeave> list = checkInLeaveService.selectCheckInLeaveList(checkInLeave);
        ExcelUtil<CheckInLeave> util = new ExcelUtil<CheckInLeave>(CheckInLeave.class);
        util.exportExcel(response, list, "老人请假管理数据");
    }

    /**
     * 获取老人请假管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leave:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(checkInLeaveService.selectCheckInLeaveById(id));
    }

    /**
     * 新增老人请假管理
     */
    @PreAuthorize("@ss.hasPermi('system:leave:add')")
    @Log(title = "老人请假管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckInLeave checkInLeave)
    {
        return toAjax(checkInLeaveService.insertCheckInLeave(checkInLeave));
    }

    /**
     * 修改老人请假管理
     */
    @PreAuthorize("@ss.hasPermi('system:leave:edit')")
    @Log(title = "老人请假管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckInLeave checkInLeave)
    {
        return toAjax(checkInLeaveService.updateCheckInLeave(checkInLeave));
    }

    /**
     * 删除老人请假管理
     */
    @PreAuthorize("@ss.hasPermi('system:leave:remove')")
    @Log(title = "老人请假管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(checkInLeaveService.deleteCheckInLeaveByIds(ids));
    }
}
